from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        CREATE TABLE IF NOT EXISTS "sys_menu" (
    "id" BIGSERIAL NOT NULL PRIMARY KEY,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "version" INT NOT NULL DEFAULT 1,
    "is_active" BOOL NOT NULL DEFAULT True,
    "is_deleted" BOOL NOT NULL DEFAULT False,
    "name" VARCHAR(100) NOT NULL,
    "title" VARCHAR(100) NOT NULL,
    "path" VARCHAR(200),
    "component" VARCHAR(200),
    "icon" VARCHAR(100),
    "parent_id" BIGINT,
    "type" VARCHAR(20) NOT NULL,
    "is_hidden" BOOL NOT NULL DEFAULT False,
    "is_keepalive" BOOL NOT NULL DEFAULT False,
    "sort_order" INT NOT NULL DEFAULT 0,
    "permission_code" VARCHAR(100),
    "description" TEXT
);
CREATE INDEX IF NOT EXISTS "idx_sys_menu_created_ec1be4" ON "sys_menu" ("created_at");
CREATE INDEX IF NOT EXISTS "idx_sys_menu_is_acti_1db9db" ON "sys_menu" ("is_active");
CREATE INDEX IF NOT EXISTS "idx_sys_menu_is_dele_73c8ce" ON "sys_menu" ("is_deleted");
CREATE INDEX IF NOT EXISTS "idx_sys_menu_parent__d50e69" ON "sys_menu" ("parent_id");
CREATE INDEX IF NOT EXISTS "idx_sys_menu_type_a37c02" ON "sys_menu" ("type");
CREATE INDEX IF NOT EXISTS "idx_sys_menu_sort_or_c9c7f3" ON "sys_menu" ("sort_order");
CREATE INDEX IF NOT EXISTS "idx_sys_menu_permiss_e39e7e" ON "sys_menu" ("permission_code");
COMMENT ON COLUMN "sys_menu"."id" IS '主键ID';
COMMENT ON COLUMN "sys_menu"."created_at" IS '创建时间';
COMMENT ON COLUMN "sys_menu"."updated_at" IS '更新时间';
COMMENT ON COLUMN "sys_menu"."version" IS '数据版本，用于乐观锁';
COMMENT ON COLUMN "sys_menu"."is_active" IS '是否有效';
COMMENT ON COLUMN "sys_menu"."is_deleted" IS '是否已删除';
COMMENT ON COLUMN "sys_menu"."name" IS '菜单名称';
COMMENT ON COLUMN "sys_menu"."title" IS '菜单标题';
COMMENT ON COLUMN "sys_menu"."path" IS '路由路径';
COMMENT ON COLUMN "sys_menu"."component" IS '组件路径';
COMMENT ON COLUMN "sys_menu"."icon" IS '图标';
COMMENT ON COLUMN "sys_menu"."parent_id" IS '父菜单ID';
COMMENT ON COLUMN "sys_menu"."type" IS '菜单类型';
COMMENT ON COLUMN "sys_menu"."is_hidden" IS '是否隐藏';
COMMENT ON COLUMN "sys_menu"."is_keepalive" IS '是否缓存';
COMMENT ON COLUMN "sys_menu"."sort_order" IS '排序';
COMMENT ON COLUMN "sys_menu"."permission_code" IS '权限编码';
COMMENT ON COLUMN "sys_menu"."description" IS '描述';
COMMENT ON TABLE "sys_menu" IS '系统菜单表';
CREATE TABLE IF NOT EXISTS "sys_permission" (
    "id" BIGSERIAL NOT NULL PRIMARY KEY,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "version" INT NOT NULL DEFAULT 1,
    "is_active" BOOL NOT NULL DEFAULT True,
    "is_deleted" BOOL NOT NULL DEFAULT False,
    "name" VARCHAR(100) NOT NULL,
    "code" VARCHAR(100) NOT NULL UNIQUE,
    "module" VARCHAR(100) NOT NULL DEFAULT 'system',
    "type" VARCHAR(20) NOT NULL,
    "resource" VARCHAR(100),
    "action" VARCHAR(50),
    "parent_id" BIGINT,
    "sort_order" INT NOT NULL DEFAULT 0,
    "description" TEXT
);
CREATE INDEX IF NOT EXISTS "idx_sys_permiss_created_cdbe16" ON "sys_permission" ("created_at");
CREATE INDEX IF NOT EXISTS "idx_sys_permiss_is_acti_c802b8" ON "sys_permission" ("is_active");
CREATE INDEX IF NOT EXISTS "idx_sys_permiss_is_dele_48a66a" ON "sys_permission" ("is_deleted");
CREATE INDEX IF NOT EXISTS "idx_sys_permiss_module_391eaa" ON "sys_permission" ("module");
CREATE INDEX IF NOT EXISTS "idx_sys_permiss_type_ac4e5a" ON "sys_permission" ("type");
CREATE INDEX IF NOT EXISTS "idx_sys_permiss_parent__5b1c04" ON "sys_permission" ("parent_id");
CREATE INDEX IF NOT EXISTS "idx_sys_permiss_sort_or_7f4d8f" ON "sys_permission" ("sort_order");
COMMENT ON COLUMN "sys_permission"."id" IS '主键ID';
COMMENT ON COLUMN "sys_permission"."created_at" IS '创建时间';
COMMENT ON COLUMN "sys_permission"."updated_at" IS '更新时间';
COMMENT ON COLUMN "sys_permission"."version" IS '数据版本，用于乐观锁';
COMMENT ON COLUMN "sys_permission"."is_active" IS '是否有效';
COMMENT ON COLUMN "sys_permission"."is_deleted" IS '是否已删除';
COMMENT ON COLUMN "sys_permission"."name" IS '权限名称';
COMMENT ON COLUMN "sys_permission"."code" IS '权限编码';
COMMENT ON COLUMN "sys_permission"."module" IS '所属模块';
COMMENT ON COLUMN "sys_permission"."type" IS '权限类型';
COMMENT ON COLUMN "sys_permission"."resource" IS '资源标识';
COMMENT ON COLUMN "sys_permission"."action" IS '操作类型';
COMMENT ON COLUMN "sys_permission"."parent_id" IS '父权限ID';
COMMENT ON COLUMN "sys_permission"."sort_order" IS '排序';
COMMENT ON COLUMN "sys_permission"."description" IS '描述';
COMMENT ON TABLE "sys_permission" IS '系统权限表';
CREATE TABLE IF NOT EXISTS "sys_role" (
    "id" BIGSERIAL NOT NULL PRIMARY KEY,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "version" INT NOT NULL DEFAULT 1,
    "is_active" BOOL NOT NULL DEFAULT True,
    "is_deleted" BOOL NOT NULL DEFAULT False,
    "name" VARCHAR(50) NOT NULL UNIQUE,
    "code" VARCHAR(50) NOT NULL UNIQUE,
    "sort_order" INT NOT NULL DEFAULT 0,
    "description" TEXT
);
CREATE INDEX IF NOT EXISTS "idx_sys_role_created_69700d" ON "sys_role" ("created_at");
CREATE INDEX IF NOT EXISTS "idx_sys_role_is_acti_145632" ON "sys_role" ("is_active");
CREATE INDEX IF NOT EXISTS "idx_sys_role_is_dele_61e497" ON "sys_role" ("is_deleted");
CREATE INDEX IF NOT EXISTS "idx_sys_role_sort_or_ee5cd7" ON "sys_role" ("sort_order");
COMMENT ON COLUMN "sys_role"."id" IS '主键ID';
COMMENT ON COLUMN "sys_role"."created_at" IS '创建时间';
COMMENT ON COLUMN "sys_role"."updated_at" IS '更新时间';
COMMENT ON COLUMN "sys_role"."version" IS '数据版本，用于乐观锁';
COMMENT ON COLUMN "sys_role"."is_active" IS '是否有效';
COMMENT ON COLUMN "sys_role"."is_deleted" IS '是否已删除';
COMMENT ON COLUMN "sys_role"."name" IS '角色名称';
COMMENT ON COLUMN "sys_role"."code" IS '角色编码';
COMMENT ON COLUMN "sys_role"."sort_order" IS '排序';
COMMENT ON COLUMN "sys_role"."description" IS '描述';
COMMENT ON TABLE "sys_role" IS '系统角色表';
CREATE TABLE IF NOT EXISTS "sys_config" (
    "id" BIGSERIAL NOT NULL PRIMARY KEY,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "version" INT NOT NULL DEFAULT 1,
    "is_active" BOOL NOT NULL DEFAULT True,
    "is_deleted" BOOL NOT NULL DEFAULT False,
    "key" VARCHAR(100) NOT NULL UNIQUE,
    "value" TEXT,
    "category" VARCHAR(50) NOT NULL,
    "type" VARCHAR(20) NOT NULL,
    "is_public" BOOL NOT NULL DEFAULT False,
    "is_readonly" BOOL NOT NULL DEFAULT False,
    "sort_order" INT NOT NULL DEFAULT 0,
    "description" TEXT
);
CREATE INDEX IF NOT EXISTS "idx_sys_config_created_929abd" ON "sys_config" ("created_at");
CREATE INDEX IF NOT EXISTS "idx_sys_config_is_acti_f7470d" ON "sys_config" ("is_active");
CREATE INDEX IF NOT EXISTS "idx_sys_config_is_dele_cc02e3" ON "sys_config" ("is_deleted");
CREATE INDEX IF NOT EXISTS "idx_sys_config_categor_53f516" ON "sys_config" ("category");
CREATE INDEX IF NOT EXISTS "idx_sys_config_sort_or_ac3774" ON "sys_config" ("sort_order");
COMMENT ON COLUMN "sys_config"."id" IS '主键ID';
COMMENT ON COLUMN "sys_config"."created_at" IS '创建时间';
COMMENT ON COLUMN "sys_config"."updated_at" IS '更新时间';
COMMENT ON COLUMN "sys_config"."version" IS '数据版本，用于乐观锁';
COMMENT ON COLUMN "sys_config"."is_active" IS '是否有效';
COMMENT ON COLUMN "sys_config"."is_deleted" IS '是否已删除';
COMMENT ON COLUMN "sys_config"."key" IS '配置键';
COMMENT ON COLUMN "sys_config"."value" IS '配置值';
COMMENT ON COLUMN "sys_config"."category" IS '配置分类';
COMMENT ON COLUMN "sys_config"."type" IS '数据类型';
COMMENT ON COLUMN "sys_config"."is_public" IS '是否公开';
COMMENT ON COLUMN "sys_config"."is_readonly" IS '是否只读';
COMMENT ON COLUMN "sys_config"."sort_order" IS '排序';
COMMENT ON COLUMN "sys_config"."description" IS '描述';
COMMENT ON TABLE "sys_config" IS '系统配置表';
CREATE TABLE IF NOT EXISTS "sys_user" (
    "id" BIGSERIAL NOT NULL PRIMARY KEY,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "version" INT NOT NULL DEFAULT 1,
    "is_active" BOOL NOT NULL DEFAULT True,
    "is_deleted" BOOL NOT NULL DEFAULT False,
    "username" VARCHAR(50) NOT NULL UNIQUE,
    "email" VARCHAR(100) NOT NULL UNIQUE,
    "phone" VARCHAR(20) UNIQUE,
    "password_hash" VARCHAR(255) NOT NULL,
    "avatar_url" VARCHAR(500),
    "nickname" VARCHAR(100),
    "bio" TEXT,
    "is_superuser" BOOL NOT NULL DEFAULT False,
    "last_login_at" TIMESTAMPTZ,
    "description" TEXT
);
CREATE INDEX IF NOT EXISTS "idx_sys_user_created_a81dcd" ON "sys_user" ("created_at");
CREATE INDEX IF NOT EXISTS "idx_sys_user_is_acti_1ce30a" ON "sys_user" ("is_active");
CREATE INDEX IF NOT EXISTS "idx_sys_user_is_dele_9423de" ON "sys_user" ("is_deleted");
CREATE INDEX IF NOT EXISTS "idx_sys_user_last_lo_89ed3f" ON "sys_user" ("last_login_at");
COMMENT ON COLUMN "sys_user"."id" IS '主键ID';
COMMENT ON COLUMN "sys_user"."created_at" IS '创建时间';
COMMENT ON COLUMN "sys_user"."updated_at" IS '更新时间';
COMMENT ON COLUMN "sys_user"."version" IS '数据版本，用于乐观锁';
COMMENT ON COLUMN "sys_user"."is_active" IS '是否有效';
COMMENT ON COLUMN "sys_user"."is_deleted" IS '是否已删除';
COMMENT ON COLUMN "sys_user"."username" IS '用户名';
COMMENT ON COLUMN "sys_user"."email" IS '邮箱';
COMMENT ON COLUMN "sys_user"."phone" IS '手机号';
COMMENT ON COLUMN "sys_user"."password_hash" IS '密码哈希';
COMMENT ON COLUMN "sys_user"."avatar_url" IS '头像URL';
COMMENT ON COLUMN "sys_user"."nickname" IS '昵称';
COMMENT ON COLUMN "sys_user"."bio" IS '个人简介';
COMMENT ON COLUMN "sys_user"."is_superuser" IS '是否超管';
COMMENT ON COLUMN "sys_user"."last_login_at" IS '最后登录时间';
COMMENT ON COLUMN "sys_user"."description" IS '描述';
COMMENT ON TABLE "sys_user" IS '系统用户表';
CREATE TABLE IF NOT EXISTS "sys_login_log" (
    "id" BIGSERIAL NOT NULL PRIMARY KEY,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "version" INT NOT NULL DEFAULT 1,
    "is_active" BOOL NOT NULL DEFAULT True,
    "is_deleted" BOOL NOT NULL DEFAULT False,
    "login_type" VARCHAR(20) NOT NULL,
    "ip_address" VARCHAR(45) NOT NULL,
    "location" VARCHAR(200),
    "device" VARCHAR(200),
    "user_agent" TEXT,
    "is_success" BOOL NOT NULL,
    "failure_reason" VARCHAR(200),
    "login_at" TIMESTAMPTZ NOT NULL,
    "logout_at" TIMESTAMPTZ,
    "description" TEXT,
    "user_id" BIGINT REFERENCES "sys_user" ("id") ON DELETE SET NULL
);
CREATE INDEX IF NOT EXISTS "idx_sys_login_l_created_21a501" ON "sys_login_log" ("created_at");
CREATE INDEX IF NOT EXISTS "idx_sys_login_l_is_acti_7bf2eb" ON "sys_login_log" ("is_active");
CREATE INDEX IF NOT EXISTS "idx_sys_login_l_is_dele_56a441" ON "sys_login_log" ("is_deleted");
CREATE INDEX IF NOT EXISTS "idx_sys_login_l_login_t_5f73e2" ON "sys_login_log" ("login_type");
CREATE INDEX IF NOT EXISTS "idx_sys_login_l_ip_addr_c6adcc" ON "sys_login_log" ("ip_address");
CREATE INDEX IF NOT EXISTS "idx_sys_login_l_is_succ_dfca4e" ON "sys_login_log" ("is_success");
CREATE INDEX IF NOT EXISTS "idx_sys_login_l_login_a_aef04b" ON "sys_login_log" ("login_at");
COMMENT ON COLUMN "sys_login_log"."id" IS '主键ID';
COMMENT ON COLUMN "sys_login_log"."created_at" IS '创建时间';
COMMENT ON COLUMN "sys_login_log"."updated_at" IS '更新时间';
COMMENT ON COLUMN "sys_login_log"."version" IS '数据版本，用于乐观锁';
COMMENT ON COLUMN "sys_login_log"."is_active" IS '是否有效';
COMMENT ON COLUMN "sys_login_log"."is_deleted" IS '是否已删除';
COMMENT ON COLUMN "sys_login_log"."login_type" IS '登录类型';
COMMENT ON COLUMN "sys_login_log"."ip_address" IS 'IP地址';
COMMENT ON COLUMN "sys_login_log"."location" IS '登录地点';
COMMENT ON COLUMN "sys_login_log"."device" IS '登录设备';
COMMENT ON COLUMN "sys_login_log"."user_agent" IS '用户代理';
COMMENT ON COLUMN "sys_login_log"."is_success" IS '是否成功';
COMMENT ON COLUMN "sys_login_log"."failure_reason" IS '失败原因';
COMMENT ON COLUMN "sys_login_log"."login_at" IS '登录时间';
COMMENT ON COLUMN "sys_login_log"."logout_at" IS '登出时间';
COMMENT ON COLUMN "sys_login_log"."description" IS '描述';
COMMENT ON COLUMN "sys_login_log"."user_id" IS '关联用户';
COMMENT ON TABLE "sys_login_log" IS '登录日志表';
CREATE TABLE IF NOT EXISTS "sys_operation_log" (
    "id" BIGSERIAL NOT NULL PRIMARY KEY,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "version" INT NOT NULL DEFAULT 1,
    "is_active" BOOL NOT NULL DEFAULT True,
    "is_deleted" BOOL NOT NULL DEFAULT False,
    "module" VARCHAR(50) NOT NULL,
    "action" VARCHAR(50) NOT NULL,
    "resource_id" VARCHAR(100),
    "resource_type" VARCHAR(50),
    "method" VARCHAR(10) NOT NULL,
    "path" VARCHAR(500) NOT NULL,
    "ip_address" VARCHAR(45) NOT NULL,
    "user_agent" TEXT,
    "request_data" JSONB,
    "response_code" INT NOT NULL,
    "response_time" INT NOT NULL,
    "description" TEXT,
    "user_id" BIGINT REFERENCES "sys_user" ("id") ON DELETE SET NULL
);
CREATE INDEX IF NOT EXISTS "idx_sys_operati_created_dc09da" ON "sys_operation_log" ("created_at");
CREATE INDEX IF NOT EXISTS "idx_sys_operati_is_acti_dcf8f5" ON "sys_operation_log" ("is_active");
CREATE INDEX IF NOT EXISTS "idx_sys_operati_is_dele_6ccb1d" ON "sys_operation_log" ("is_deleted");
CREATE INDEX IF NOT EXISTS "idx_sys_operati_ip_addr_6d1172" ON "sys_operation_log" ("ip_address");
CREATE INDEX IF NOT EXISTS "idx_sys_operati_module_7d6f1a" ON "sys_operation_log" ("module", "action");
CREATE INDEX IF NOT EXISTS "idx_sys_operati_resourc_9e6fc0" ON "sys_operation_log" ("resource_type", "resource_id");
COMMENT ON COLUMN "sys_operation_log"."id" IS '主键ID';
COMMENT ON COLUMN "sys_operation_log"."created_at" IS '创建时间';
COMMENT ON COLUMN "sys_operation_log"."updated_at" IS '更新时间';
COMMENT ON COLUMN "sys_operation_log"."version" IS '数据版本，用于乐观锁';
COMMENT ON COLUMN "sys_operation_log"."is_active" IS '是否有效';
COMMENT ON COLUMN "sys_operation_log"."is_deleted" IS '是否已删除';
COMMENT ON COLUMN "sys_operation_log"."module" IS '操作模块';
COMMENT ON COLUMN "sys_operation_log"."action" IS '操作类型';
COMMENT ON COLUMN "sys_operation_log"."resource_id" IS '资源ID';
COMMENT ON COLUMN "sys_operation_log"."resource_type" IS '资源类型';
COMMENT ON COLUMN "sys_operation_log"."method" IS '请求方法';
COMMENT ON COLUMN "sys_operation_log"."path" IS '请求路径';
COMMENT ON COLUMN "sys_operation_log"."ip_address" IS 'IP地址';
COMMENT ON COLUMN "sys_operation_log"."user_agent" IS '用户代理';
COMMENT ON COLUMN "sys_operation_log"."request_data" IS '请求数据';
COMMENT ON COLUMN "sys_operation_log"."response_code" IS '响应码';
COMMENT ON COLUMN "sys_operation_log"."response_time" IS '响应时间(ms)';
COMMENT ON COLUMN "sys_operation_log"."description" IS '描述';
COMMENT ON COLUMN "sys_operation_log"."user_id" IS '操作用户';
COMMENT ON TABLE "sys_operation_log" IS '操作日志表';
CREATE TABLE IF NOT EXISTS "sys_user_settings" (
    "id" BIGSERIAL NOT NULL PRIMARY KEY,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "version" INT NOT NULL DEFAULT 1,
    "is_active" BOOL NOT NULL DEFAULT True,
    "is_deleted" BOOL NOT NULL DEFAULT False,
    "theme" VARCHAR(20) NOT NULL DEFAULT 'light',
    "language" VARCHAR(10) NOT NULL DEFAULT 'zh-CN',
    "sidebar_collapsed" BOOL NOT NULL DEFAULT False,
    "page_size" INT NOT NULL DEFAULT 20,
    "timezone" VARCHAR(50) NOT NULL DEFAULT 'Asia/Shanghai',
    "notification_email" BOOL NOT NULL DEFAULT True,
    "notification_sms" BOOL NOT NULL DEFAULT False,
    "custom_settings" JSONB,
    "description" TEXT,
    "user_id" BIGINT NOT NULL REFERENCES "sys_user" ("id") ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS "idx_sys_user_se_created_5f1a26" ON "sys_user_settings" ("created_at");
CREATE INDEX IF NOT EXISTS "idx_sys_user_se_is_acti_adf292" ON "sys_user_settings" ("is_active");
CREATE INDEX IF NOT EXISTS "idx_sys_user_se_is_dele_c7b711" ON "sys_user_settings" ("is_deleted");
COMMENT ON COLUMN "sys_user_settings"."id" IS '主键ID';
COMMENT ON COLUMN "sys_user_settings"."created_at" IS '创建时间';
COMMENT ON COLUMN "sys_user_settings"."updated_at" IS '更新时间';
COMMENT ON COLUMN "sys_user_settings"."version" IS '数据版本，用于乐观锁';
COMMENT ON COLUMN "sys_user_settings"."is_active" IS '是否有效';
COMMENT ON COLUMN "sys_user_settings"."is_deleted" IS '是否已删除';
COMMENT ON COLUMN "sys_user_settings"."theme" IS '主题设置';
COMMENT ON COLUMN "sys_user_settings"."language" IS '语言设置';
COMMENT ON COLUMN "sys_user_settings"."sidebar_collapsed" IS '侧边栏折叠';
COMMENT ON COLUMN "sys_user_settings"."page_size" IS '每页显示数量';
COMMENT ON COLUMN "sys_user_settings"."timezone" IS '时区设置';
COMMENT ON COLUMN "sys_user_settings"."notification_email" IS '邮件通知';
COMMENT ON COLUMN "sys_user_settings"."notification_sms" IS '短信通知';
COMMENT ON COLUMN "sys_user_settings"."custom_settings" IS '自定义配置';
COMMENT ON COLUMN "sys_user_settings"."description" IS '描述';
COMMENT ON COLUMN "sys_user_settings"."user_id" IS '关联用户';
COMMENT ON TABLE "sys_user_settings" IS '用户配置表';
CREATE TABLE IF NOT EXISTS "aerich" (
    "id" SERIAL NOT NULL PRIMARY KEY,
    "version" VARCHAR(255) NOT NULL,
    "app" VARCHAR(100) NOT NULL,
    "content" JSONB NOT NULL
);
CREATE TABLE IF NOT EXISTS "sys_role_sys_permission" (
    "sys_role_id" BIGINT NOT NULL REFERENCES "sys_role" ("id") ON DELETE CASCADE,
    "permission_id" BIGINT NOT NULL REFERENCES "sys_permission" ("id") ON DELETE CASCADE
);
COMMENT ON TABLE "sys_role_sys_permission" IS '角色权限';
CREATE UNIQUE INDEX IF NOT EXISTS "uidx_sys_role_sy_sys_rol_8629c3" ON "sys_role_sys_permission" ("sys_role_id", "permission_id");
CREATE TABLE IF NOT EXISTS "sys_user_sys_role" (
    "sys_user_id" BIGINT NOT NULL REFERENCES "sys_user" ("id") ON DELETE CASCADE,
    "role_id" BIGINT NOT NULL REFERENCES "sys_role" ("id") ON DELETE CASCADE
);
COMMENT ON TABLE "sys_user_sys_role" IS '用户角色';
CREATE UNIQUE INDEX IF NOT EXISTS "uidx_sys_user_sy_sys_use_8c8e6a" ON "sys_user_sys_role" ("sys_user_id", "role_id");"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        """
